﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Stock_In_View.aspx.cs" Inherits="JKF.Web.Stock.In.Stock_In_View" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>产品/耗材入库管理页面</title>
        <%= RegScript("~/js/jquery.1.5.js")%>
        <%= RegScript("~/js/jquery.js")%> 
        <%= RegScript("~/js/jquery.nhis.js")%>
        <%= RegScript("~/js/jquery.rchis.js")%>
        <%= RegScript("~/js/jquery-ui-custom.min.js")%>
        <%= RegScript("~/js/css.js")%>
        <%= RegScript("~/js/DatePicker/WdatePicker.js")%>
        <%= RegScript("~/js/Common.js")%>
        <%= RegScript("~/js/Jquery.commonGrid.js")%>
        <%= RegScript("~/js/jquery-form.js") %>
        <script src="/js/Uppop/tipswindown2.js"  type="text/javascript"></script>
    <link href="/App_Themes/Theme2/Include.css"   rel="stylesheet" type="text/css" />
      
    <script type="text/javascript">

        $(function () {
            // 注册搜索文本框的回车事件
            $('#txt_Complex,#txt_DATE_IN_START,#txt_DATE_IN_END').keyup(function (event) {
                enterHandler(event, 'btn_search');
            });
            //注册选择产品分类/产品名称的单击事件  
            $('#txt_type_product').click(function () {
                product_keys = ''; //清空查询条件
                window.parent.pop("选择产品类别/产品名称", '<%= ResolveUrl("~/Stock/Stock_View_Product_Sort_Tree.aspx") %>', 300, 300, getSelectProduct_Sort);
            });

        });
        //弹出层 
        function addProductStockIn(id) {
            window.parent.pop("产品入库登记", '<%= ResolveUrl("~/Stock/In/Stock_In_Add.aspx?moduleKey=") %>' + id, 950, 300, updateList);
        }
        //回调函数，弹出层保存成功之后执行，更新列表中数据，或往列表中添加新录的数据
        function updateList(obj, id) {

            if ($.FxNull(id, "").length > 0) {//修改成功返回对应的ID
                $("#tb tbody tr[key='" + id + "']").html($(obj).html());

            } else {//添加成功返回"" 空字符串就可以了
                if ($('#emptyTr')) { // 如果存在的话
                    $('#emptyTr').remove(); // 当添加成功的话，移除此行
                }
                addCount(); //添加成功之后更新记录总条数
                $('#tb tbody').prepend(obj);
            }
        }
        
    </script>
          <script type="text/javascript">
              var product_keys = '<%=P("rk_product_key") %>'; //选择的产品的ID或者从url参数中读取
              var product_name = '<%=P("rk_product_name") %>'; //从url参数中读取
              var AppPath = '<%=AppPath %>';
              var handler = AppPath + '/do/Stock/Stock_In.do';
              var PageSize = 10;
              var pager = null;
              $(function () {
                  if (product_name&&product_name.length>0) {
                      $('#txt_type_product').val(product_name);
                  }
                  // 生成树结构
                  //initTree();
                  // 组织查询条件
                  var searchData = {
                      ActionName: 'GetSTOCK_INS',
                      PRODUCT_KEY: product_keys, // 产品名称ID,或者从url参数中读取
                      NAME: '', //产品名称
                      PRODUCT_NUMS: '', //数量
                      IN_NO: '', //入库单号
                      REAL_NAME: '', //操作员
                      MEMO: '', //备注
                      DATA_START: $('#txt_DATE_IN_START').val(),
                      DATA_END: $('#txt_DATE_IN_END').val(),
                      PageIndex: 1,
                      PageSize: 10
                  };
                  //处理项目选择查询
                  getSearchItem('#itemSelect',searchData);
                  // 分页异步请求
                  pager = $('#divPager').pager(AppPath, handler, function () {
                      return searchData;
                  }, function (data) {
                      var tbody = $('#tb tbody');
                      tbody.empty();
                      if (data && data.Entity && data.Entity.length) {
                          data = data.Entity
                          var tr, td;
                          for (var i = 0; i < data.length; i++) {
                              var item = data[i];
                              tr = $("<tr key=" + item.IN_KEY + "></tr>").appendTo(tbody);

                              $('<td></td>').appendTo(tr).html('<input style="display:<%=DispEdit%>"  class="common_btn_edit mr12"  type="button" onclick="addProductStockIn(' + "'" + item.IN_KEY + "'" + ')" /><input name="" type="button" class="common_btn_del mr12"  style="display:<%=DispDelete%>"/>');
                              $('<td></td>').appendTo(tr).text(item.IN_NO); // 入库单号
                              $('<td></td>').appendTo(tr).text(item.SORT_NAME); // 产品类别名称
                              $('<td></td>').appendTo(tr).text(item.NAME); // 产品名称
                              $('<td></td>').appendTo(tr).text(item.PRODUCT_NUMS); // 数量
                              $('<td></td>').appendTo(tr).text(item.MEMO); // 备注
                              $('<td></td>').appendTo(tr).text(item.USER_CREATE); // 操作员
                              $('<td></td>').appendTo(tr).text(item.DATE_IN); // 入库日期 
                          }
                      } else {
                          tbody.html('<tr id="emptyTr"><td colspan="9" style="text-align: center">没有数据!</td></tr>');
                      }
                      //这里动态获取高度
                      var tbHeight = $(window).height() - $(".common_search").height() - $("#divPager").height() - 38;
                      tbHeight = tbHeight < 300 ? 300 : tbHeight;

                      //var tbHeight = $(window).height() - $(".common_search").height() - $("#divPager").height() - 70;

                      $("#tb").H8_Grid($("#divPager"), tbHeight);
                  }, PageSize, true);
                  // 删除一条记录
                  $('input.common_btn_del').live('click', function () {
                      if (!confirm("确认删除吗?")) {
                          return false;
                      }
                      var tr = $(this).parent().parent();
                      $.post(handler, { ActionName: 'DeleteSTOCK_IN', id: tr.attr('key') }, function (obj) {
                          if (obj.MessageCode == "Error") {
                              alert(obj.Message);
                              return;
                          } //else if (obj.MessageCode == "2") {
                          //alert("删除失败。\r\n原因：总店创建产品分店无权删除！只能查看");
                          //}
                          else if (obj.MessageCode == "Ok" && obj.Success) { // 返回1，才允许删除
                              tr.remove();
                              reduceCount(); //删除成功之后减少记录总条数 
                          }
                      }, 'json');
                  });
                  // 查询 
                  $('#btn_search').click(function () {
                      //处理入库日期查询
                      searchData.DATA_START = $('#txt_DATE_IN_START').val();
                      searchData.DATA_END = $('#txt_DATE_IN_END').val();
                      // 获取产品类别/产品名称ID
                      searchData.PRODUCT_KEY = product_keys;
                      $('#itemSelect').change();
                      pager.option.pageIndex = 1;
                      pager.getPegerData();
                      return false;
                  });
              });
              //导出Excel
              function exportExcel() {
                  //$("#btn_search").click();
                  var v = $('div.common_search').gform();
                  v.ActionName ='GetSTOCK_INS';
                  v.PRODUCT_KEY=product_keys; // 产品名称ID,或者从url参数中读取
                  v.NAME= ''; //产品名称
                  v.PRODUCT_NUMS = '';  //数量
                  v.IN_NO = '';  //入库单号
                  v.REAL_NAME = ''; //操作员
                  v.MEMO = '';  //备注
                  v.DATA_START = $('#txt_DATE_IN_START').val();
                  v.DATA_END = $('#txt_DATE_IN_END').val();
                  getSearchItem('#itemSelect', v);
                  v.isExport = "1";
                  $.formP(handler, v);
              }
              //获取选中节点
              function getSelectProduct_Sort(treeObj, id) {
                  product_keys = '';
                  $('#txt_type_product').val('选择/修改');
                  if (treeObj.length > 0) {
                      var check_three_nodes_id = '';
                      var check_three_nodes_name = '';
                      for (var i = 0; i < treeObj.length; i++) {
                          check_three_nodes_id += treeObj[i].ID + ',';
                          check_three_nodes_name += treeObj[i].NAME + ',';
                      }
                      product_keys = check_three_nodes_id.substr(0, check_three_nodes_id.length - 1);
                      check_three_nodes_name = check_three_nodes_name.substr(0, check_three_nodes_name.length - 1);
                      $('#txt_type_product').val(check_three_nodes_name).attr('title', check_three_nodes_name);
                  }
              }

              //处理查询选项
              function getSearchItem(obj, searchData) {
                  $(obj).change(function () { 
                      if ($(this).val() == '-1') {
                          searchData.PRODUCT_NUMS = '';
                          searchData.IN_NO = '';
                          searchData.REAL_NAME = '';
                          searchData.MEMO = '';
                          searchData.NAME = '';
                      }
                      if ($(this).val() == 'PRODUCT_NUMS') {
                          $('#termSelect').val('2').attr('disabled', 'disabled');
                          searchData.PRODUCT_NUMS = $('#txt_Complex').val();
                          searchData.IN_NO = '';
                          searchData.REAL_NAME = '';
                          searchData.MEMO = '';
                          searchData.NAME = '';
                      } else {
                          $('#termSelect').val('1').attr('disabled', 'disabled');
                          if ($(this).val() == 'IN_NO') {
                              searchData.IN_NO = $('#txt_Complex').val();
                              searchData.PRODUCT_NUMS = '';
                              searchData.REAL_NAME = '';
                              searchData.MEMO = '';
                              searchData.NAME = '';
                          } else if ($(this).val() == 'REAL_NAME') {
                              searchData.REAL_NAME = $('#txt_Complex').val();
                              searchData.IN_NO = '';
                              searchData.PRODUCT_NUMS = '';
                              searchData.MEMO = '';
                              searchData.NAME = '';
                          } else if ($(this).val() == 'MEMO') {
                              searchData.MEMO = $('#txt_Complex').val();
                              searchData.IN_NO = '';
                              searchData.PRODUCT_NUMS = '';
                              searchData.REAL_NAME = '';
                              searchData.NAME = '';
                          } else if ($(this).val() == 'NAME') {
                              searchData.NAME = $('#txt_Complex').val();
                              searchData.MEMO = '';
                              searchData.IN_NO = '';
                              searchData.PRODUCT_NUMS = '';
                              searchData.REAL_NAME = '';
                          }
                      }
                  }); 
              }
          </script>
</head>
<body>
     <div class="warrper_body"> 
        <!--隐藏域中保存当前虚拟路径以便发送ajax异步请求时用-->
        <input id="AppPath" name="AppPath" type="hidden" value="<%=AppPath%>" />
        
        <div class="index" style=" overflow:hidden">
            <div class="common_search">
                 <div class="l_h45">   
            产品类别/产品名称：<input type="button" id="txt_type_product" class="common_btn_gaoji115" value="选择/修改"/>
             
            查询项：<select id="itemSelect">
                 <option value="-1">全部</option> 
                 <option value="NAME">产品名称</option> 
                 <option value="IN_NO">入库单号</option> 
                 <option value="REAL_NAME">操作员</option>
                 <option value="MEMO">备注</option>
                 <option value="PRODUCT_NUMS">数量</option>
            </select>
            <select id="termSelect">
                 <option value="1">包含</option>
                 <option value="2">=</option>
            </select>
            <input type="text" id="txt_Complex" style="width: 80px" />   
            入库日期：<input type="text" style="width: 80px" id="txt_DATE_IN_START" onfocus="WdatePicker()" />至<input type="text" id="txt_DATE_IN_END" onfocus="WdatePicker()" style="width: 80px" />

                    <span class="mr30"><input name="" id="btn_search" type="button"  class="common_btn_search"/></span>
                    <span class="mr30"<input id="Button3" type="button" class="common_btn_add2" style="display: <%=DispAdd%>;"  onclick="addProductStockIn('')"  /></span>
                    <span class="mr30"><input name="" id="btn_export" class="btn_style" type="button" value="导出excel" onclick="exportExcel()"/></span>
                 </div>
            </div>
            <div class="l_h7"></div>
           
            <div class="index_table"  >
                <table id="tb" width="100%" class="common_table">
                    <thead>
                        <tr>
                             <th width="100px" orderaction="false">操作</th>
                                <th width="120px" ordertype="string">入库单号</th>
                                 <th width="100px" ordertype="string">产品类别</th>
                                <th width="160px" ordertype="string">产品名称</th>
                                <th width="100px" ordertype="string">入库数量</th>
                                <th width="100px" ordertype="string">备注</th> 
                                 <th width="100px" ordertype="string">操作员</th> 
                                 <th width="100px" ordertype="string">入库日期</th>  
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td colspan="8" style="text-align: center">点击搜索查看数据</td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div class="page" id="divPager"></div>      
        </div>
    </div> 
</body>
</html>
